#ifndef CSVHELPER_H
#define CSVHELPER_H

#include <QString>
class QTextStream;
class QFile;
class SACsvStreamPrivate;
class  CsvHelper
{

public:
    CsvHelper(QTextStream* txt);
    CsvHelper(QFile* txt);
    virtual ~CsvHelper();
    //转换为标识csv字符
    static QString ToCsvString(const QString& rawStr);
    //把一行要用逗号分隔的字符串转换为一行标准csv字符串
    static QString ToCsvStringLine(const QStringList& sectionLine);
    //解析一行csv字符
    static QStringList FromCsvLine(const QString &lineStr);
    CsvHelper & operator << (const QString &str);
    CsvHelper & operator << (int d);
    CsvHelper & operator << (double d);
    CsvHelper & operator << (float d);
    //另起一行
    void NewLine();
    //获取输入输出流
    QTextStream* stream() const;
    //读取并解析一行csv字符串
    QStringList ReadCsvLine();
    //判断是否到文件末端
    bool AtEnd() const;
private:
    static int Advquoted(const QString &s, QString &fld, int i);
    static int Advplain(const QString &s, QString &fld, int i);
private:
    SACsvStreamPrivate* d_p;
};
typedef CsvHelper & (*SACsvWriterFunction)(CsvHelper &);
inline CsvHelper &operator<<(CsvHelper &s, SACsvWriterFunction f)
{
    return (*f)(s);
}
CsvHelper &endl(CsvHelper &s);

#endif // CSVHELPER_H
